Ext.onReady(function() {
	
	//显示提示信息
	Ext.QuickTips.init();
	
	//统一设置提示风格，为side
	Ext.form.Field.prototype.msgTarget='side';	
	
	//片路径：一张1×1的透明图片，Ext使用它来和CSS一起创建内嵌的图标。 
	Ext.BLANK_IMAGE_URL = '../extjs/resources/images/default/s.gif';
	
	//checkbox选择模型
	var selModel = new Ext.grid.CheckboxSelectionModel();
	
	//数据源
 	var approvingTroubleTicketStore = new Ext.data.JsonStore({
			url: '../personnelRequirement/approvingList.action',
			fields: ['_id', 'stationName', 'department', 'recruitNum', 'recruitReason', 'positionTime','createTime','happenTime','status'],
			root: 'data', 
			totalProperty: 'total' 
		});
	approvingTroubleTicketStore.load({
		params: {
			start: 0,
			limit: 10
		}
	});	
	
	//checkbox选择模型
	var selModel = new Ext.grid.CheckboxSelectionModel();
	
	//列模型
	var colModel = new Ext.grid.ColumnModel([
		new Ext.grid.RowNumberer({header: '序号', width: 35}), //加入序号
		selModel, //加入checkbox选择模型
		{header: '岗位名称', width: 100, dataIndex: 'stationName', sortable: true},
		{header: '部门名称', width: 100, dataIndex: 'department', sortable: true},
		{header: '招聘人数', width: 100, dataIndex: 'recruitNum', sortable: true},
		{header: '招聘原因', width: 100, dataIndex: 'recruitReason', sortable: true},
		{header: '到岗时间', width: 100, dataIndex: 'positionTime', sortable: true},
		{header: '发生时间', width: 100, dataIndex: 'happenTime', sortable: true},
		{header: '创建时间', width: 100, dataIndex: 'createTime', sortable: true},
		{header: '状态', width: 100, dataIndex: 'status', sortable: true}
	]);
	colModel.defaultWidth  = 100;
	
	var approvingTroubleTicketGrid = new Ext.grid.GridPanel({
		title: '待审核申请表单列表',
		height: 450,
		autoWidth: true, 
		viewConfig: new Ext.grid.GridView({
			autoFill: true  
		}),
		stripeRows: true, 
		sm: selModel, 
		frame: true, 
		applyTo: 'approvingIndex_div',
		store: approvingTroubleTicketStore,
		cm: colModel, //列模型
		tbar: new Ext.Toolbar([
			{text: '审批单据', icon: '../images/add.gif', handler: showBills},
			{text: '审批历史', icon: '../images/viewHistory.gif', handler: viewHistory_lo}
		]),
		bbar: new Ext.PagingToolbar({
			store: approvingTroubleTicketStore, 
			pageSize: 10,
			displayInfo: true,
			plugins: new Ext.ux.ProgressBarPager()
		})
	});
	
	
	
			
	var approveInfoForm = new Ext.form.FormPanel({
		frame: true,
		buttonAlign: 'center',
		items:[
			{
				xtype: 'hidden',
				id: 'troubleTicketId',
				name: 'approveInfo1.perReq._id'
			},
			{
				xtype:'hidden',
				id:'to_where',
				name:'to_where'
			},
			{
				xtype: 'textarea',
				fieldLabel: '审批意见',
				width: 200,
				name: 'approveInfo1.desc',
				allowBlank: false
			}
		],
		buttons: [
			{text: '确定', icon: '../images/save.gif', handler: doSave},
			{text: '取消', icon: '../images/cancel.gif', handler: function(){
				win.hide();
			}}
//			{text: '拒绝', icon: '../images/close.gif', handler: doDel}
		]
	});
	
	var win = new Ext.Window({
		width: 350,
		height: 150,
		items: [approveInfoForm],
		modal: true, //模态
		resizable: false, //禁制调整窗口大小
		closeAction: 'hide' //不销毁form对象，只是隐藏
	});
	
	function showAdd() {
		var records = approvingTroubleTicketGrid.getSelectionModel().getSelections();
		if (records.length == 0) {
			Ext.Msg.alert('提示', '请选择单据！');	
		}else if (records.length > 1) {
			Ext.Msg.alert('提示', '一次只能选择一条单据！');
		}else {
			win.setTitle('添加审批意见');
			win.show();
			approveInfoForm.getForm().reset();
			Ext.getDom('troubleTicketId').value = records[0].get('_id');
			Ext.getDom('to_where').value = 'agree';
		}	
	}
	
	function showDel(){
		var records = approvingTroubleTicketGrid.getSelectionModel().getSelections();
		if (records.length == 0) {
			Ext.Msg.alert('提示', '请选择单据！');	
		}else if (records.length > 1) {
			Ext.Msg.alert('提示', '一次只能选择一条单据！');
		}else {
			win.setTitle('添加审批意见');
			win.show();
			approveInfoForm.getForm().reset();
			Ext.getDom('troubleTicketId').value = records[0].get('_id');
			Ext.getDom('to_where').value = 'reject';
		}	
	}
	
	function doSave() {
		var to_where = Ext.getDom('to_where').value;
		var url = '../approve_new/';
		if(to_where == 'agree'){
			url+='add';
		}else if(to_where == 'reject'){
			url+='del';
		}
		else{
			alert('审批url不能为空');
			return;
		}
		approveInfoForm.getForm().submit({
			url: url,
			method: 'POST',
			clientValidation: true,
			waitTitle: '提示',
			waitMsg: '正在保存数据，请稍后...',
			success: function() {
				approvingTroubleTicketStore.reload(); //重新加载数据
				Ext.Msg.alert('提示', '审批成功！', function() {
					win.hide();
					billWin.hide();
				});
			},
			failure: function() {
				Ext.Msg.alert('提示', '审批失败！');
			}
		});			
	}
	
	/////////////////////////////////////////////////////////////////////////
	
	var data1=[[1,"计算机1"],[2,"计算机2"],[3,"计算机3"],[4,"计算机4"]];
	 var major = new Ext.data.ArrayStore({
                //设定读取的地址
              //  proxy: new Ext.data.HttpProxy({ url: '/App_Ashx/Demo/City.ashx' }),
                //设定读取的格式    
               // reader: new Ext.data.JsonReader({ root: 'data' },
                 //[{ name: 'id' }, { name: 'name'}])
               data:data1,
               fields:["id","name"]
            });
	
	var myTroubleTicketForm=new Ext.form.FormPanel({
	       width : 890,
	       buttonAlign :'right',
	       autoHeight : true,
	       frame : true,
	       layout : "form", // 整个大的表单是form布局
	       labelWidth :5,
	       labelAlign : "right",
	    
	       items:[
	       //第一行
			{
				id: '_id',
				name: 'personnelReq._id',
				xtype: 'hidden'
			},
	       {
	       collapsible :true,
	       title:"招聘申请",
	       items:[
	       {layout:'column',
	      frame :true,
	    
	     items:[
	       {
	    	
	        columnWidth :0.5,
	       layout:'form',
	        
	      
	        labelWidth :90,
	       items:[{
	       xtype:'combo',
	       fieldLabel: '申请&nbsp&nbsp招聘&nbsp部门',
	        store: major,
	        width: 205,
	         displayField: 'depName',
	        valueField: 'depId',
	         triggerAction: 'all',
	         
	         blankText: '请选择部门',
	         editable: false,
	         mode: 'local', //该属性和以下方法为了兼容ie8
	         emptyText: '请选择...',
	         store: new Ext.data.JsonStore({ 
						url: '../department/findList.action',
						fields: ['depId', 'depName'],
						autoLoad: true //自动调用load方法
					}),
					id:'department.depId',
	       hiddenName: 'personnelReq.department.depId'
	        }]},{
	        columnWidth :0.5,
	       layout:'form',
	       
	       margin: '5 0 5 0',

	        labelWidth :90,
	       items:[{
	     
	        
	        xtype : "textfield",
	          fieldLabel : "招聘岗位名称",
	          name: 'personnelReq.stationName',
	          id:'stationName',
	        width : 205,
	        
	        blankText: '请填写岗位名称'
	       }]}]},

	       //第二行
	{layout:'column',

	frame :true,
	///
	columnWidth :0.5,

	items:[{
	        columnWidth :0.5,
	       layout:'form',
	       labelWidth :90,
	       items:[{
	        
	          margin: '10 20 5 7',
	          xtype: 'numberfield',     
	          fieldLabel: "人&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp数",     
	         name: 'personnelReq.recruitNum',
	         id:'recruitNum',
	              emptyText: "--请选择--",  
	              triggerAction: "all",//请设置为"all",否则默认为"query"的情况下，你选择某个值后，再此下拉时，只出现匹配选项，如果设为"all"的话，每次下拉均显示全部选项  
	                mode: "local",  
	                width: 205,
	               typeAhead: true, //延时查询  
	                typeAheadDelay:3000,  
	                editable: true,//可以编辑
	                 
	                 minValue : 0,//可输入的最小值
	                 blankText: '请输入人数'
	                  }]}
	                ,{
	      columnWidth :0.5,
	       layout:'form',
	         
	     
	         labelWidth :90,
	        
	       items:[{
	       
	      format : 'Y-m-d',
	      readOnly : true ,
	        xtype : "datefield",
	              fieldLabel : "需到 岗 时  间",
	              width : 205,
	              id:'time',
	      name:'personnelReq.positionTime',
	      id:'positionTime',
	       
	               
	                 blankText: '请选择到岗时间'
	       }] }
	               ]
	               ///ting
	       },
	       {
	       //a1
	     
	       layout:'column',
	      frame :true,
	       //
	       items:[
	       {//b1
	       layout:'form',
	         columnWidth :0.5,
	       
	        
	         labelWidth :90,
	       items:[{
	       width: 290,
	        xtype : "textarea",
	       
	        
	          name: 'personnelReq.recruitReason',
	        id:'recruitReason',
	               fieldLabel : '<div style="margin-top:25px">招 &nbsp聘&nbsp&nbsp &nbsp&nbsp原&nbsp 因:</div>',
	              labelSeparator :'',
	                 
	               
	                 blankText: '请输入招聘原因'
	           }] 
	       }//b1
	       ,{ //b2
	       layout:'form',
	    
	       labelWidth :90,
	       columnWidth :0.5,
	       
	       items:[{
	        xtype:"textarea",
	             name: 'personnelReq.jobExplain',
	             id:'jobExplain',
	              fieldLabel : '<div style="margin-top:25px">说&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp明:</div>',
	              labelSeparator :'',
	               width : 290
	             
	             }]
	       }//b2
	       ]},
	       { 
	    frame :true,
	       layout:'form',
	      
	       items:[{
	        layout:'form',
	     
	       labelWidth :90,
	       columnWidth :0.5,
	       items:[{
	       xtype:'textarea',
	     id:'jobDescription',
	       name: 'personnelReq.jobDescription',
	      fieldLabel : '<div style="margin-top:25px">职&nbsp&nbsp位&nbsp&nbsp&nbsp&nbsp&nbsp描&nbsp&nbsp述:</div>',
	              labelSeparator :'',
	                 
	               
	                 blankText: '请输入职位描述',
	       width:725
	       }]
	       }]
	       }]
	       }
	       
	        //第二行结束
	       ,
	       //第三行
	       {collapsible :true,
	       
	        title:'任职条件',
	       
	       items:[{ 
	     frame :true,
	       layout:'column',
	      
	       items:[
	       {layout:'form',
	        style : 'border:0px solid black; border-top:0;',
	       
	       columnWidth:0.5,
	       
	       labelWidth :90,
	       items:[
	       { 
	       
	       xtype:'combo',
	       fieldLabel: '专&nbsp业 &nbsp&nbsp&nbsp&nbsp要 &nbsp求',
	        store: major,
	        width:205,
	         displayField: 'name',
	        valueField: 'id',
	        hiddenName: 'personnelReq.proReq',
	        id:'proReq',
	         triggerAction: 'all',
	         allowBlank:true,
	        editable: false,
	         mode: 'local', //该属性和以下方法为了兼容ie8
	        emptyText: '请选择...'
	        }]},{ 
	       
	        layout:'form',
	        columnWidth:0.5,
	       
	        labelWidth :90, 
	        items:[{
	       xtype:'combo',
	       fieldLabel: '工 作 经 验',
	        store: major,
	        width: 205,
	        displayField: 'name',
	        valueField: 'id',
	        hiddenName: 'personnelReq.workExp',
	        id:'workExp',
	         triggerAction: 'all',
	         allowBlank:true,
	        editable: false,
	         mode: 'local', //该属性和以下方法为了兼容ie8
	        emptyText: '请选择...'
	        }]}]
	       }, 
	       { 
	      frame :true,
	       layout:'column',
	    
	       items:[
	       { 
	        layout:'form',
	        columnWidth:0.5,
	        labelWidth :90, 
	        items:[{frame : false,
	        xtype:'combo',
	       fieldLabel: ' 年 &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp&nbsp&nbsp 龄',
	        store: major,
	        width: 205,
	     
	        displayField: 'name',
	        valueField: 'id',
	         triggerAction: 'all',
	         hiddenName: 'personnelReq.age',
	         id:'age',
	         allowBlank:true,
	        editable: false,
	         mode: 'local', //该属性和以下方法为了兼容ie8
	        emptyText: '请选择...'
	        }]}, {
	        columnWidth:0.5,
	         labelWidth :90,
	         layout:'form',   
	         items:[{ 
	         width:205,
	 
	         xtype:'radiogroup',
	         fieldLabel:' 性&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp别',
	                 items: [{ name: 'personnelReq.sex',id:'sex', inputValue: '0', boxLabel: '男' }, { id:'sex',name: 'personnelReq.sex',width:30, inputValue: '1',boxLabel: '女'},{ id:'sex',name: 'personnelReq.sex', inputValue: '2',boxLabel: '不限', checked: true }]
	                  
	                  }]}]
	       },{
	       layout:'column',
	    
	      frame :true,
	       items:[
	       {
	        
	        columnWidth:0.5,
	         labelWidth :90,
	         layout:'form',
	         items:[{
	       xtype:"textarea",
	               name: 'personnelReq.quality',
	               id:'quality',
	               fieldLabel : '<div style="margin-top:10px">能力&nbsp&nbsp&nbsp&nbsp/&nbsp&nbsp&nbsp素质:</div>',
	              labelSeparator :'',
	              width :290,
	             height:40
	              }]
	              },	
	       {
	        
	        
	        columnWidth:0.5,
	         labelWidth :90,
	         layout:'form',
	         items:[{
	       xtype:"textarea",
	             frame : true,
	              fieldLabel : '<div style="margin-top:10px">技能&nbsp&nbsp&nbsp&nbsp要求:</div>',
	              labelSeparator :'',
	              width : 290,
	              height:40,
	                name: 'personnelReq.tecRequest',
	                id:'tecRequest'
	            }]
	              }
	       
	       ]// 
	       }
	       ]}

	       //第三行结束
	       
	       ,{
	       collapsible :true,
	       layout:'form',
	       title:'意见',
	       collapsed:true,
	       //
	      
	      id:'yijian',
	       items:[
	    	   {
	      frame :true,
	        layout:'column',
	       items:[
	       {labelWidth :90,
	       layout:'form',
	       columnWidth:0.5,
	       items:[{
	       name: 'personnelReq.depMgrOpinion',
	       id:'depMgrOpinion',
	       xtype:"textarea",
	       fieldLabel : '<div style="margin-top:10px">部门&nbsp经理&nbsp&nbsp意见:</div>',
	       labelSeparator :'',
	       width:290,
	        height:40
	             }]},
	             {
	            	
	        labelWidth :90,
	       layout:'form',
	       columnWidth:0.5, 
	      
	        items:[{
	         xtype:"textarea",
	              name: 'personnelReq.leaOption',
	              id:'leaOption',
	              fieldLabel : '<div style="margin-top:10px">上级&nbsp&nbsp&nbsp&nbsp主管:</div>',
	              labelSeparator :'',
	            
	             width:290,
	              height:40
	             }]}
	             
	             ]
	          },
	          
	       
	       { frame :true,
	        
	       layout:'column',
	       items:[
	        {   
	      
	        labelWidth :90,
	       layout:'form',
	       columnWidth:0.5,
	        
	        items:[{
	             xtype:"textarea",
	           name: 'personnelReq.hrOption',
	           id:'hrOption',
	               fieldLabel : '<div style="margin-top:10px">人力资源部意见:</div>',
	              labelSeparator :'',
	           
	             width :290,
	              height:40
	              
	              }]
	               
	       },{
	        
	        labelWidth :90,
	       layout:'form',
	       columnWidth:0.5,
	      
	        items:[{
	         xtype:"textarea",
	          name: 'personnelReq.hrLeaOption',
	          id:'hrLeaOption',
	            fieldLabel : '<div style="margin-top:0px">人力资源部主管领导意见:</div>',
	              labelSeparator :'',
	          
	             width :290,
	              height:40
	            
	              }]
	       }
	       
	       ]
	       }
	       ]
	       //
	       },
	       //第四行结束
	       {collapsed:true,
	        collapsible :true,
	       layout:'form',
	       title:'签字',
	       //
	      
	       items:[
	        { frame :true,
	       layout:'column', 
	      
	       items:[
	        {
	         labelWidth :90,
	       layout:'form',
	       columnWidth:0.5,
	        
	        items:[{
	        	id:'viceGeMgrOption',
	        	  name: 'personnelReq.viceGeMgrOption',
	       xtype:"textarea",
	              fieldLabel : '<div style="margin-top:10px">副&nbsp&nbsp总&nbsp&nbsp&nbsp&nbsp&nbsp意&nbsp&nbsp见:</div>',
	              labelSeparator :'',
	            
	              width :290,
	              height:40
	             
	              }]
	       },{
	       labelWidth :90,
	       layout:'form',
	       columnWidth:0.5,
	        
	        items:[{
	         xtype:"textarea",
	         id:'viceGeMgrSign',
	        name: 'personnelReq.viceGeMgrSign',
	              fieldLabel : '<div style="margin-top:10px">签&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp名:</div>',
	              labelWidth :90,
	              labelSeparator :'',
	              width :290,
	              height:40
	            }]
	              
	       }
	       
	       ]
	       },
	     { 
	       frame :true,
	     
	       layout:'column',
	       items:[
	        { 
	         labelWidth :90,
	       layout:'form',
	       columnWidth:0.5,
	        
	        items:[{
	        	id:'geMgrOption',
	        	  name: 'personnelReq.geMgrOption',
	       xtype:"textarea",
	              fieldLabel : '<div style="margin-top:10px">总&nbsp经&nbsp理&nbsp&nbsp&nbsp意&nbsp见:</div>',
	              labelSeparator :'',
	             
	             width :290,
	              height:40
	              
	             }]
	       },{
	labelWidth :90,
	       layout:'form',
	       columnWidth:0.5,
	       
	        items:[{
	         xtype:"textarea",
	         id:'geMgrSign',
	           name: 'personnelReq.geMgrSign',
	              fieldLabel : '<div style="margin-top:10px">签&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp名:</div>',
	              labelSeparator :'',
	              width :290,
	              height:40
	             
	              }]
	       }
	       
	       ]
	       }
	       
	       
	       ]
	       //
	       },
	       {title:'注：此表由用人部门填写，经人力资源部审核，报总经理批示后执行。'
	       }
	       //第五行结束
	       ]
	       });
	
	var billWin = null;
	/**
	 * 1:表示列表
	 * 2：表示单据上面
	 */
	function viewHistory_lo(){
		var _id = "";
		var records = approvingTroubleTicketGrid.getSelectionModel().getSelections();
		if (records.length == 0) {
			Ext.Msg.alert('提示', '请选择单据！');	
		}else if (records.length > 1) {
			Ext.Msg.alert('提示', '一次只能选择一条单据！');
		}
		_id = records[0].get('_id');
		viewHistory(_id);
	}
	
	function showBills() {
		var records = approvingTroubleTicketGrid.getSelectionModel().getSelections();
		if (records.length == 0) {
			Ext.Msg.alert('提示', '请选择单据！');	
		}else if (records.length > 1) {
			Ext.Msg.alert('提示', '一次只能选择一条单据！');
		}else {
			if(isBlank(billWin)){
				createBillWin();
			}
			billWin.setTitle('用人申请表');
			billWin.show();
			myTroubleTicketForm.getForm().load({
				url: '../personnelRequirement/edit.action',
				method: 'GET',
				params: {'personnelReq._id': records[0].get('_id')},
				waitTitle: '提示',
				waitMsg: '正在装载招聘申请数据，请稍后...',
				failure: function() {
					Ext.Msg.alert('提示', '装载部门数据失败！');
				}
			});
		}	
	}
	
	function createBillWin(){
		billWin = new Ext.Window({
			width: 930,
			height: 800,
			y:0,
			x:0,
			contrain :true,
			tbar: new Ext.Toolbar([
		                   			{text: '同意', icon: '../images/delete.gif',handler:showAdd},
		                   			{text: '驳回', icon: '../images/dispatch.gif',handler:showDel},
		                   			{text: '审批历史', icon: '../images/viewHistory.gif',handler: viewHistory_lo}
		                   			]),
			items: [myTroubleTicketForm],
			resizable: false,
	        closable: true,
	        autoScroll : true,
	        draggable :false,//拖动  
	        modal:true,
	        maximizable: true,
	        minimizable: true,
	        frame : true,
			closeAction: 'hide' //不销毁form对象，只是隐藏
		});
	}
		
});